package lib;

import java.io.Serializable;


/**
 * Class representing a command such as CreateUser, etc
 *
 * @author abhip
 *
 */
public class Command implements Serializable
{
    /**
     * serialVersionUID is a universal version identifier for a Serializable
     * class. Deserialization uses this number to ensure that a loaded class
     * corresponds exactly to a serialized object. If no match is found during
     * deserialization, an InvalidClassException is thrown.
     */
	private static final long serialVersionUID = 3783099900454184928L;
	private Serializable commandArgs[];
    private String commandName;

    public Command(String commandName, Serializable[] commandArgs) 
    {
        ArgumentValidator.IsNotNullOrEmpty("commandName", commandName);
        // Command arguments could be null

        this.commandName = commandName;
        this.commandArgs = commandArgs;
    }

    /**
     * Gets the arguments of the command
     *
     * @return commandArgs
     */
    public Serializable[] CommandArgs() 
    {
        return commandArgs;
    }

    /**
     * Gets the name of the command
     *
     * @return commandName
     */
    public String CommandName() 
    {
        return commandName;
    }

    /**
     * Converts Command to String
     *
     * @return string representation of a command
     */
    @Override
    public String toString() 
    {
        StringBuilder sb = new StringBuilder();
        sb.append("commandName: ");
        sb.append(commandName);
        sb.append(" args:");

        if (commandArgs != null) 
        {
            for (int i = 0; i < commandArgs.length; ++i) 
            {
                sb.append(commandArgs[i]);
                sb.append(" ");
            }
        }

        return sb.toString();
    }
}
